<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :title="'体系文件'" :editModel="editModel" :api="api" :form="form"
      :formRules="formRules" @onSave="onSave" @onSaved="saveInfo" :autoSave="false">
      <dym-form :editModel="editModel" :componentList="componentList" :formValue.sync="form"
        ></dym-form>
    </dialog-edit>
  </div>
</template>

<script>
  import BaseDialog from '@/pages/BaseDialog'
  import DialogEdit from '@/components/dialog/DialogEdit'
  import dymForm from '@/components/element/dymForm'
  import { fileManageApi } from '@/api/business/businessApi'
  export default {
    extends: new BaseDialog(),
    components: {
      DialogEdit,
      dymForm,
      fileManageApi
    },
    data () {
      return {
        officeOptions: [],
        // 需要显示的每一项定义在这里
        componentList: [
          {
            label: '体系名称',
            prop: 'docName', // 表单验证传入的值
            componentName: 'el-input',
            cols: [12, 12, 12, 12],
            placeholder: '请输入',
            value: 'docName' // 字段显示的值
          },
          {
            label: '体系编码',
            prop: 'docCode',
            componentName: 'el-input',
            cols: [12, 12, 12, 12],
            placeholder: '请输入',
            value: 'docCode'
          },
          {
            label: '所属单位',
            prop: 'oweOrgName',
            componentName: 'el-input',
            cols: [12, 12, 12, 12],
            placeholder: '请输入',
            value: 'oweOrgName'
          },
          // {
          //   label: '公开对象',
          //   prop: 'openTarget',
          //   componentName: 'dict',
          //   dictTypeCode: 'openTarget',
          //   cols: [12, 12, 12, 12],
          //   placeholder: '请先选择',
          //   value: 'openTarget'
          // },
          {
            label: '体系摘要',
            prop: 'docAbstract',
            componentName: 'el-input',
            type: 'textarea',
            cols: [24, 24, 24, 24],
            placeholder: '请输入',
            value: 'docAbstract'
          },
          {
            label: '备注',
            prop: 'remarks',
            componentName: 'el-input',
            type: 'textarea',
            cols: [24, 24, 24, 24],
            placeholder: '请输入',
            value: 'remarks'
          }
        ],
        // 表单验证
        formRules: {
          // 表单字段名：[规则]
          docName: [{ required: true, message: '必填', trigger: 'blur' }, {
            min: 1,
            max: 200,
            message: '长度在 1 到 200 个字符'
          }],
          docCode: [{ required: true, message: '必填', trigger: 'blur' }, {
            min: 1,
            max: 64,
            message: '长度在 1 到 64 个字符'
          }],
          oweOrgId: [{ required: true, message: '必填', trigger: 'blur' }],
          openTarget: [{ required: true, message: '必填', trigger: 'blur' }],
          oweOrgName: [ {
            min: 1,
            max: 255,
            message: '长度在 1 到 255 个字符'
          }],
          remarks: [ {
            min: 1,
            max: 300,
            message: '长度在 1 到 300 个字符'
          }]
        }
      }
    },
    methods: {
      saveInfo () {
        let id = this.form.id
        if (id) {
          fileManageApi.update(id, this.form).then(res => {
              if (res.code === 0) {
                this.dialogVisible = false
                this.$emit('handSearch')
                this.success('修改成功')
              } else if (res.code === -1) {
                this.error(res.msg)
              }
          })
        } else {
          fileManageApi.create(this.form).then(res => {
            if (res.code === 0) {
              this.dialogVisible = false
              this.$emit('handSearch')
              this.success('新增成功')
            } else if (res.code === -1) {
              this.error(res.msg)
            }
          })
        }
      }
    }
  }
</script>
